import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/special_goods_arr.dart';
import 'package:xinxuan/common/special_underline_tab_indicator.dart';
import 'package:xinxuan/controllers/special_controller/xingxuan_special_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class XingxuanSpecialPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '星选专区',
        backgroundColor: bgWhiteColor,
      ),
      body: GetBuilder<XingxuanSpecialPageController>(
        init: XingxuanSpecialPageController(),
        builder: (controller) {
          return Column(
            children: [
              Container(
                width: 375.w,
                height: 122.h,
                alignment: Alignment.center,
                margin: EdgeInsets.symmetric(vertical: 12.h),
                child: Image.asset(
                  'assets/images/image_special_bg.png',
                  width: 351.w,
                  height: 122.h,
                  fit: BoxFit.fill
                ),
              ),
              Expanded(child: controller.typeArr.length <= 0 ? Container() : DefaultTabController(
                length: controller.typeArr.length, 
                child: Column(
                  children: [
                    Container(
                      height: 57.h,
                      constraints: BoxConstraints(maxHeight: 57.h),
                      child: Material(
                        color: bgWhiteColor,
                        child: TabBar(     
                          indicatorPadding: EdgeInsets.only(bottom: 11.h, left: 6.w),           
                          indicator: SpecialUnderlineTabIndicator(
                            wantWidth: 42.w,
                            borderSide: BorderSide(
                              width: 6.h,
                              color: bgMainColor
                            )
                          ),
                          indicatorColor: bgMainColor,
                          labelColor: mainTextColor,
                          unselectedLabelColor: textSubtitleColor,
                          labelStyle: TextStyle(
                            fontSize: 14.sp
                          ),
                          unselectedLabelStyle: TextStyle(
                            fontSize: 14.sp
                          ),
                          onTap: (index) {
                            controller.tabIndex.value = index;
                            // controller.price.value = controller.activityStarsVo.value.meta!.priceArea![index].value!;
                            controller.getActivityStarsItem(showLoading: true);
                          },
                          labelPadding: EdgeInsets.zero,
                          tabs: controller.typeArr.map((item) {
                            return Tab(
                              text: item.label,
                            );
                          }).toList()
                        ),
                      ),
                    ),
                    // Expanded(child: TabBarView(
                    //   physics: NeverScrollableScrollPhysics(),
                    //   children: controller.dataArr.map((item) {
                    //     return SpecialGoodsArr(
                    //       goodsArr: item.data!,
                    //       xingxuanSpecialPageController: controller,
                    //     );
                    //   }).toList(),
                    // ))
                    Expanded(child: Obx(() => SpecialGoodsArr(
                      goodsArr: controller.dataArr[controller.tabIndex.value].data!,
                      xingxuanSpecialPageController: controller,
                    )))
                  ],
                )
              ))
            ],
          );
        },
      ),
    );
  }
}